package com.jusda.message;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jusda.message.api.external.UpdateClient;
import com.jusda.message.entity.UserScore;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author yiyi
 * @Date 2022/3/14-下午5:10
 * @Description:
 */
@Component
@Slf4j
//@RocketMQMessageListener(consumerGroup = "${spring.application.name}", topic = "rocketmq-service",consumeMode = ConsumeMode.ORDERLY,consumeThreadMax = 2)
public class RocketListener implements RocketMQListener<Object> {
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private UpdateClient updateClient;

    @SneakyThrows
    @Override
    public void onMessage(Object message) {
        log.info("收到消息:{}", message);
        UserScore userScore = objectMapper.readValue(message.toString(), UserScore.class);
        updateClient.updateUserScore(userScore);
    }
}
